package com.liuzhihang.doc.view.utils;

public class UnicodeConverter {
    public static String unicodeToString(String unicode) {
        StringBuilder sb = new StringBuilder();
        String[] hex = unicode.split("\\\\u");

        for (int i = 1; i < hex.length; i++) {
            int code = Integer.parseInt(hex[i], 16);
            sb.append((char) code);
        }
        return sb.toString();
    }

    public static String toUnicode(String str) {
        StringBuilder sb = new StringBuilder();
        for (char c : str.toCharArray()) {
            // 非ASCII字符转换为Unicode格式
            if (c > 127) {
                sb.append("\\u").append(String.format("%04x", (int) c));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }



    public static void main(String[] args) {
        String unicode = ",";
        System.out.println(unicodeToString(unicode)); // 输出: 接口名称

       // System.out.println( toUnicode("请求参数")); // 输出: 接口名称
    }
}